package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.commons.util.ReflectUtil;
import net.zigin.nhi.could.waste.dto.WarnTimeDto;
import net.zigin.nhi.could.waste.model.WarnTime;
import net.zigin.nhi.could.waste.service.WarnTimeService;

import net.zigin.nhi.could.waste.vo.JsonForResult;
import net.zigin.nhi.could.waste.vo.WarnTimeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * WarnTime控制器类
 * @ClassName: WarnTimeController
 * @author mgw1986
 * @date 2021-9-20 19:47:11
 * @version V1.0
 */
@Api(tags = "超时预警管理")
@RestController
@RequestMapping("/warnTime")
public class WarnTimeController extends BaseController {
	@Autowired
	private WarnTimeService warnTimeService;

	@PostMapping("/save")
	@ApiOperation("保存或编辑超时预警")
	@ApiImplicitParam(name = "warnTimeDto", value = "超时预警信息", required = true, dataType = "WarnTimeDto")
	public JsonForResult<String> save(@RequestBody WarnTimeDto warnTimeDto){
		String id = warnTimeService.saveOrUpdate(warnTimeDto);
		return JsonForResult.<String>builder().data(id).success(true).build();
	}

	@GetMapping("/get")
	@ApiOperation("超时预警详情")
	public JsonForResult<WarnTimeVo> getById(){
		WarnTime warnTime = warnTimeService.getOne();
		WarnTimeVo warnTimeVo = ReflectUtil.copyProperties(warnTime, WarnTimeVo.class);
		return JsonForResult.<WarnTimeVo>builder().data(warnTimeVo).success(true).build();
	}

}
